class Solution:
    def majorityElement(self, nums) -> int:
        votes = 0
        for num in nums:
            if votes == 0: x = num
            votes += 1 if num == x else -1
        return x
nums = [1,2,3,2,2,2,5,4,2]
r = Solution().majorityElement(nums)
print(r)